﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi
{
    /// <summary>
    /// 更新维度信息
    /// </summary>
    [CPPEI.WebApi.AuthPostAction("Dim", "Update", "1.0")]
    public class UpdateAction : BaseAction<UpdateParams, UpdateResult>
    {
        protected override ActionResult<UpdateResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            UpdateParams opParams)
        {
            SER.DimService service = new SER.DimService();
            ServiceResult result = service.UpdateDim(context.UserId, opParams.DimId, opParams.Code, opParams.Name);
            if(result.IsSuccess)
            {
                return new ActionResult<UpdateResult>(null);
            }
            else
            {
                return new ActionResult<UpdateResult>(result.IsSuccess, result.ErrorCode, result.Message, null);
            }
        }
    }

    public class UpdateParams
    {
        [Parameter]
        public Guid DimId { get; set; }

        public string Code { get; set; }

        public string Name { get; set; }
    }

    public class UpdateResult
    {
    }
}
